<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

include 'securities.php';

class Manage_config extends Securities {

	function __construct() {
		parent::__construct('manage_config');
		$this -> form_validation -> set_error_delimiters('<span class="error">', '</span>');
	}

	public function index() {
		$data['title'] = $this->lang->line('title_store_config');
		$this -> form_validation -> set_rules('company', 'lang:config_company', 'required');
		$this -> form_validation -> set_rules('email', 'lang:config_email', 'required|valid_email');
		$this -> form_validation -> set_rules('address', 'lang:config_address', 'required');
		$this -> form_validation -> set_rules('phone', 'lang:config_phone', 'required');

		if ($this -> form_validation -> run() === FALSE) {
			$this -> load -> view(B_MASTER . 'index', $data);
		} else {

			$module_id = $this -> uri -> segment(1);
			if (!$this -> is_has_modify_permission($module_id)) {
				redirect('ctm-common/no-allow-modify/' . $module_id);
			}
			$data = array('company' => $this -> input -> post('company'), 'address' => $this -> input -> post('address'), 'email' => $this -> input -> post('email'), 'employee' => $this -> input -> post('employee'), 'hand_phone' => $this -> input -> post('hand_phone'), 'language' => $this -> input -> post('language'), 'phone' => $this -> input -> post('phone'), 'website' => $this -> input -> post('website'));

			$is_updated = $this -> mod_config -> batch_save($data);
			if ($is_updated) {
				$this -> session -> set_flashdata('success', 'Company information was updated success');
				redirect('manage-config');
			} else {
				$this -> session -> set_flashdata('error', 'Company information was updated success');
				redirect('manage-config');
			}
		}
	}

}
